<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
  <meta name="theme-color" content="#222">
  <meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

  <link rel="stylesheet" href="/css/main.css">



  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

  <script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {
      "hostname": "holidaypenguin.gitee.io",
      "root": "/",
      "images": "/images",
      "scheme": "Mist",
      "version": "8.2.2",
      "exturl": false,
      "sidebar": {
        "position": "right",
        "display": "always",
        "padding": 18,
        "offset": 12
      },
      "copycode": true,
      "bookmark": {
        "enable": false,
        "color": "#222",
        "save": "auto"
      },
      "fancybox": false,
      "mediumzoom": false,
      "lazyload": false,
      "pangu": false,
      "comments": {
        "style": "tabs",
        "active": null,
        "storage": true,
        "lazyload": false,
        "nav": null
      },
      "motion": {
        "enable": true,
        "async": true,
        "transition": {
          "post_block": "fadeIn",
          "post_header": "fadeInDown",
          "post_body": "fadeInDown",
          "coll_header": "fadeInLeft",
          "sidebar": "slideUpIn"
        }
      },
      "prism": false,
      "i18n": {
        "placeholder": "搜索...",
        "empty": "没有找到任何搜索结果：${query}",
        "hits_time": "找到 ${hits} 个搜索结果（用时 ${time} 毫秒）",
        "hits": "找到 ${hits} 个搜索结果"
      },
      "path": "/search.xml",
      "localsearch": {
        "enable": true,
        "trigger": "auto",
        "top_n_per_article": 1,
        "unescape": false,
        "preload": false
      }
    };
  </script>
  <meta property="og:type" content="article">
  <meta property="og:title" content="理解BFC">
  <meta property="og:url" content="https://holidaypenguin.gitee.io/blob/2019-01-08-understanding-bfc/index.html">
  <meta property="og:site_name" content="HolidayPenguin">
  <meta property="og:locale" content="zh_CN">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/019.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/020.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/021.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/022.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/023.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/024.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/025.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/026.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/027.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/028.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/029.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/030.png">
  <meta property="og:image" content="https://holidaypenguin.gitee.io/images/css/031.png">
  <meta property="article:published_time" content="2019-01-08T10:07:29.000Z">
  <meta property="article:modified_time" content="2019-01-08T10:07:29.000Z">
  <meta property="article:author" content="holidaypenguin">
  <meta property="article:tag" content="BFC">
  <meta property="article:tag" content="Block Formatting Context">
  <meta name="twitter:card" content="summary">
  <meta name="twitter:image" content="https://holidaypenguin.gitee.io/images/css/019.png">


  <link rel="canonical" href="https://holidaypenguin.gitee.io/blob/2019-01-08-understanding-bfc/">


  <script class="page-configurations">
    // https://hexo.io/docs/variables.html
    CONFIG.page = {
      sidebar: "",
      isHome: false,
      isPost: true,
      lang: 'zh-CN'
    };
  </script>
  <title>理解BFC | HolidayPenguin</title>





  <noscript>
    <style>
      body {
        margin-top: 2rem;
      }

      .use-motion .menu-item,
      .use-motion .sidebar,
      .use-motion .post-block,
      .use-motion .pagination,
      .use-motion .comments,
      .use-motion .post-header,
      .use-motion .post-body,
      .use-motion .collection-header {
        visibility: visible;
      }

      .use-motion .header,
      .use-motion .site-brand-container .toggle,
      .use-motion .footer {
        opacity: initial;
      }

      .use-motion .site-title,
      .use-motion .site-subtitle,
      .use-motion .custom-logo-image {
        opacity: initial;
        top: initial;
      }

      .use-motion .logo-line {
        transform: scaleX(1);
      }

      .search-pop-overlay,
      .sidebar-nav {
        display: none;
      }

      .sidebar-panel {
        display: block;
      }
    </style>
  </noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner">
        <div class="site-brand-container">
          <div class="site-nav-toggle">
            <div class="toggle" aria-label="切换导航栏" role="button">
              <span class="toggle-line"></span>
              <span class="toggle-line"></span>
              <span class="toggle-line"></span>
            </div>
          </div>

          <div class="site-meta">

            <a href="/" class="brand" rel="start">
              <i class="logo-line"></i>
              <h1 class="site-title">HolidayPenguin</h1>
              <i class="logo-line"></i>
            </a>
          </div>

          <div class="site-nav-right">
            <div class="toggle popup-trigger">
              <i class="fa fa-search fa-fw fa-lg"></i>
            </div>
          </div>
        </div>



        <nav class="site-nav">
          <ul class="main-menu menu">
            <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
            <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
            <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
            <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
            <li class="menu-item menu-item-search">
              <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
              </a>
            </li>
          </ul>
        </nav>



        <div class="search-pop-overlay">
          <div class="popup search-popup">
            <div class="search-header">
              <span class="search-icon">
                <i class="fa fa-search"></i>
              </span>
              <div class="search-input-container">
                <input autocomplete="off" autocapitalize="off" maxlength="80" placeholder="搜索..." spellcheck="false" type="search" class="search-input">
              </div>
              <span class="popup-btn-close" role="button">
                <i class="fa fa-times-circle"></i>
              </span>
            </div>
            <div class="search-result-container no-result">
              <div class="search-result-icon">
                <i class="fa fa-spinner fa-pulse fa-5x"></i>
              </div>
            </div>

          </div>
        </div>

      </div>


      <div class="toggle sidebar-toggle" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
      </div>

      <aside class="sidebar">

        <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
          <ul class="sidebar-nav">
            <li class="sidebar-nav-toc">
              文章目录
            </li>
            <li class="sidebar-nav-overview">
              站点概览
            </li>
          </ul>

          <div class="sidebar-panel-container">
            <!--noindex-->
            <div class="post-toc-wrap sidebar-panel">
              <div class="post-toc animated">
                <ol class="nav">
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%9A%E4%B9%89"><span class="nav-number">1.</span> <span class="nav-text">定义</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#BFC%E7%9A%84%E5%8E%9F%E7%90%86"><span class="nav-number">2.</span> <span class="nav-text">BFC的原理</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#BFC%E7%9A%84%E5%8A%9F%E8%83%BD"><span class="nav-number">3.</span> <span class="nav-text">BFC的功能</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%9D%97%E6%A0%BC%E5%BC%8F%E5%8C%96%E4%B8%8A%E4%B8%8B%E6%96%87%E6%96%B9%E5%BC%8F"><span class="nav-number">4.</span> <span class="nav-text">创建块格式化上下文方式</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%9E%E7%8E%B0"><span class="nav-number">5.</span> <span class="nav-text">实现</span></a>
                    <ol class="nav-child">
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#html%EF%BC%88%E6%A0%B9%E5%85%83%E7%B4%A0%E6%88%96%E5%8C%85%E5%90%AB%E6%A0%B9%E5%85%83%E7%B4%A0%E7%9A%84%E5%85%83%E7%B4%A0%EF%BC%89"><span class="nav-number">5.1.</span> <span class="nav-text">html（根元素或包含根元素的元素）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#float-none%EF%BC%88%E6%B5%AE%E5%8A%A8%E5%85%83%E7%B4%A0%EF%BC%89"><span class="nav-number">5.2.</span> <span class="nav-text">float!&#x3D;none（浮动元素）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#position-absolute%E3%80%81fixed%EF%BC%88%E7%BB%9D%E5%AF%B9%E5%AE%9A%E4%BD%8D%E5%85%83%E7%B4%A0%EF%BC%89"><span class="nav-number">5.3.</span> <span class="nav-text">position&#x3D;absolute、fixed（绝对定位元素）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#display-inline-block%EF%BC%88%E8%A1%8C%E5%86%85%E5%9D%97%E7%BA%A7%E5%85%83%E7%B4%A0%EF%BC%89"><span class="nav-number">5.4.</span> <span class="nav-text">display&#x3D;inline-block（行内块级元素）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#display-table-cell%EF%BC%88%E8%A1%A8%E6%A0%BC%E5%8D%95%E5%85%83%E6%A0%BC%EF%BC%89"><span class="nav-number">5.5.</span> <span class="nav-text">display&#x3D;table-cell（表格单元格）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#display-table-caption%EF%BC%88%E8%A1%A8%E6%A0%BC%E6%A0%87%E9%A2%98%EF%BC%89"><span class="nav-number">5.6.</span> <span class="nav-text">display&#x3D;table-caption（表格标题）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#display-some-value%EF%BC%88%E5%8C%BF%E5%90%8D%E8%A1%A8%E6%A0%BC%E5%8D%95%E5%85%83%E6%A0%BC%E5%85%83%E7%B4%A0%EF%BC%89"><span class="nav-number">5.7.</span> <span class="nav-text">display&#x3D;some value（匿名表格单元格元素）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#overflow-visible"><span class="nav-number">5.8.</span> <span class="nav-text">overflow!&#x3D;visible</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#display-flow-root"><span class="nav-number">5.9.</span> <span class="nav-text">display&#x3D;flow-root</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#contain-layout%E3%80%81content%E3%80%81strict"><span class="nav-number">5.10.</span> <span class="nav-text">contain&#x3D;layout、content、strict</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#display-flex%E3%80%81inline-flex%EF%BC%88%E5%BC%B9%E6%80%A7%E5%85%83%E7%B4%A0%EF%BC%89"><span class="nav-number">5.11.</span> <span class="nav-text">display&#x3D;flex、inline-flex（弹性元素）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#display-grid%E3%80%81inline-grid%EF%BC%88%E7%BD%91%E6%A0%BC%E5%85%83%E7%B4%A0%EF%BC%89"><span class="nav-number">5.12.</span> <span class="nav-text">display&#x3D;grid、inline-grid（网格元素）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#column-count%E3%80%81column-width-auto%EF%BC%88%E5%A4%9A%E5%88%97%E5%AE%B9%E5%99%A8%EF%BC%89"><span class="nav-number">5.13.</span> <span class="nav-text">column-count、column-width!&#x3D;auto（多列容器）</span></a></li>
                      <li class="nav-item nav-level-3"><a class="nav-link" href="#column-span-all"><span class="nav-number">5.14.</span> <span class="nav-text">column-span&#x3D;all</span></a></li>
                    </ol>
                  </li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%80%BB%E7%BB%93"><span class="nav-number">6.</span> <span class="nav-text">总结</span></a></li>
                  <li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="nav-number">7.</span> <span class="nav-text">应用场景</span></a></li>
                </ol>
                </li>
                <li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8F%82%E8%80%83"><span class="nav-number"></span> <span class="nav-text">参考</span></a>
              </div>
            </div>
            <!--/noindex-->

            <div class="site-overview-wrap sidebar-panel">
              <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
                <p class="site-author-name" itemprop="name">holidaypenguin</p>
                <div class="site-description" itemprop="description"></div>
              </div>
              <div class="site-state-wrap site-overview-item animated">
                <nav class="site-state">
                  <div class="site-state-item site-state-posts">
                    <a href="/archives/">

                      <span class="site-state-item-count">138</span>
                      <span class="site-state-item-name">日志</span>
                    </a>
                  </div>
                  <div class="site-state-item site-state-categories">
                    <a href="/categories/">

                      <span class="site-state-item-count">26</span>
                      <span class="site-state-item-name">分类</span></a>
                  </div>
                  <div class="site-state-item site-state-tags">
                    <a href="/tags/">

                      <span class="site-state-item-count">234</span>
                      <span class="site-state-item-name">标签</span></a>
                  </div>
                </nav>
              </div>
              <div class="links-of-author site-overview-item animated">
                <span class="links-of-author-item">
                  <a href="https://github.com/holidaypenguin" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;holidaypenguin" rel="noopener" target="_blank"><i class="github fa-fw"></i>GitHub</a>
                </span>
                <span class="links-of-author-item">
                  <a href="mailto:songshipeng2016@gmail.com" title="E-Mail → mailto:songshipeng2016@gmail.com" rel="noopener" target="_blank"><i class="envelope fa-fw"></i>E-Mail</a>
                </span>
              </div>



            </div>
          </div>
        </div>
      </aside>
      <div class="sidebar-dimmer"></div>


    </header>


    <div class="back-to-top" role="button">
      <i class="fa fa-arrow-up"></i>
      <span>0%</span>
    </div>

    <noscript>
      <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
    </noscript>


    <div class="main-inner post posts-expand">





      <div class="post-block">



        <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
          <link itemprop="mainEntityOfPage" href="https://holidaypenguin.gitee.io/blob/2019-01-08-understanding-bfc/">

          <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
            <meta itemprop="image" content="/images/avatar.gif">
            <meta itemprop="name" content="holidaypenguin">
            <meta itemprop="description" content="">
          </span>

          <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
            <meta itemprop="name" content="HolidayPenguin">
          </span>
          <header class="post-header">
            <h1 class="post-title" itemprop="name headline">
              理解BFC
            </h1>

            <div class="post-meta-container">
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>

                  <time title="创建时间：2019-01-08 18:07:29" itemprop="dateCreated datePublished" datetime="2019-01-08T18:07:29+08:00">2019-01-08</time>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-folder"></i>
                  </span>
                  <span class="post-meta-item-text">分类于</span>
                  <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                    <a href="/categories/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
                  </span>
                </span>


                <span id="/blob/2019-01-08-understanding-bfc/" class="post-meta-item leancloud_visitors" data-flag-title="理解BFC" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
              </div>

              <div class="post-description">
                <!-- more -->
              </div>
            </div>
          </header>




          <div class="post-body" itemprop="articleBody">
            <h2 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h2>
            <p>** 块格式化上下文（Block Formatting Context，BFC） **是Web页面的可视化CSS渲染的一部分，是布局过程中生成块级盒子的区域，也是浮动元素与其他元素的交互限定区域。</p>
            <p>A ** block formatting context ** is a part of a visual CSS rendering of a Web page. It is the region in which the layout of block boxes occurs and in which floats interact with other elements.</p>
            <h2 id="BFC的原理"><a href="#BFC的原理" class="headerlink" title="BFC的原理"></a>BFC的原理</h2>
            <ol>
              <li>内部的box会在垂直方向，一个接一个的放置。</li>
              <li>每个元素的margin box的左边，与包含块border box的左边相接触（对于从左往右的格式化，否则相反）。即使存在浮动也是如此。</li>
              <li>box垂直方向的距离由margin决定，属于同一个bfc的两个相邻box的margin会发生重叠。</li>
              <li>bfc的区域不会与浮动区域的box重叠。</li>
              <li>bfc是一个页面上的独立的容器，外面的元素不会影响bfc里的元素，反过来，里面的也不会影响外面的。</li>
              <li>计算bfc高度的时候，浮动元素也会参与计算。</li>
            </ol>
            <h2 id="BFC的功能"><a href="#BFC的功能" class="headerlink" title="BFC的功能"></a>BFC的功能</h2>
            <p>你可以将BFC看作是页面中的一个迷你布局。一旦元素创建了一个BFC，它其中的所有元素都会被它包裹。正如我们所见的，当盒子变成BFC之后，它内部的浮动元素就再也不可能突破它的底部（也就是说，盒子不再会因内部元素浮动而坍塌）。</p>
            <h2 id="创建块格式化上下文方式"><a href="#创建块格式化上下文方式" class="headerlink" title="创建块格式化上下文方式"></a>创建块格式化上下文方式</h2>
            <ul>
              <li>根元素或包含根元素的元素</li>
              <li>浮动元素（元素的 <code>float</code> 不是 `none）</li>
              <li>绝对定位元素（元素的 <code>position</code> 为 <code>absolute</code> 或 <code>fixed</code>）</li>
              <li>行内块元素（元素的 <code>display</code> 为 <code>inline-block</code>）</li>
              <li>表格单元格（元素的 <code>display</code>为 <code>table-cell</code>，HTML表格单元格默认为该值）</li>
              <li>表格标题（元素的 <code>display</code> 为 <code>table-caption</code>，HTML表格标题默认为该值）</li>
              <li>匿名表格单元格元素（元素的 <code>display</code>为 <code>table</code>、<code>table-row</code>、 <code>table-row-group</code>、<code>table-header-group</code>、<code>table-footer-group</code>（分别是HTML <code>table</code>、<code>row</code>、<code>tbody</code>、<code>thead</code>、<code>tfoot</code>的默认属性）或 <code>inline-table</code>）</li>
              <li><code>overflow</code> 值不为 <code>visible</code> 的块元素</li>
              <li><code>display</code> 值为 <code>flow-root</code> 的元素</li>
              <li><code>contain</code> 值为 <code>layout</code>、<code>content</code>或 <code>strict</code> 的元素</li>
              <li>弹性元素（<code>display</code>为 <code>flex</code> 或 <code>inline-flex</code>元素的直接子元素）</li>
              <li>网格元素（<code>display</code>为 <code>grid</code> 或 <code>inline-grid</code> 元素的直接子元素）</li>
              <li>多列容器（元素的 <code>column-count</code> 或 <code>column-width</code> 不为 <code>auto</code>，包括 <code>column-count</code> 为 <code>1</code>）</li>
              <li><code>column-span</code> 为 <code>all</code> 的元素始终会创建一个新的BFC，即使该元素没有包裹在一个多列容器中（标准变更，Chrome bug）</li>
            </ul>
            <h2 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h2>
            <h3 id="html（根元素或包含根元素的元素）"><a href="#html（根元素或包含根元素的元素）" class="headerlink" title="html（根元素或包含根元素的元素）"></a>html（根元素或包含根元素的元素）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  .root-bfc&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;root-bfc&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span> </span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>

            <p><img src="" data-original="/images/css/019.png" alt="019"></p>
            <p><code>html</code>根元素不因为内部元素的<code>margin</code>外溢，而<code>body</code>元素会外溢</p>
            <h3 id="float-none（浮动元素）"><a href="#float-none（浮动元素）" class="headerlink" title="float!=none（浮动元素）"></a>float!=none（浮动元素）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  .float-wrap&#123;</span><br><span class="line"><span class="css">    <span class="attribute">overflow</span>: hidden;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .float-left&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">float</span>: left;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .float-right&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">float</span>: right;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;float-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;float-left&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;float-right&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span> </span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/020.png" alt="020"></p>
            <p>添加float之后会产生浮动脱离文档流，这时根据需要在外层清除浮动；如果在body元素清除浮动，<code>overflow</code>以外的方法都可以使用</p>
            <h3 id="position-absolute、fixed（绝对定位元素）"><a href="#position-absolute、fixed（绝对定位元素）" class="headerlink" title="position=absolute、fixed（绝对定位元素）"></a>position=absolute、fixed（绝对定位元素）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  .position-wrap&#123;</span><br><span class="line">  &#125;</span><br><span class="line">  .position-absolute&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">position</span>: absolute;</span></span><br><span class="line"><span class="css">    <span class="attribute">top</span>: <span class="number">10px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">left</span>: <span class="number">10px</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .position-fixed&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">position</span>: fixed;</span></span><br><span class="line"><span class="css">    <span class="attribute">right</span>: <span class="number">10px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">top</span>: <span class="number">10px</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;position-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;position-absolute&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;position-fixed&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span> </span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/021.png" alt="021"></p>
            <p>定位之后margin不会消失，但是会脱离文档流</p>
            <p>如果不加位置数据，同样可以实现bfc，后续内容要使用<code>margin-top</code>撑开，等其他方法</p>
            <h3 id="display-inline-block（行内块级元素）"><a href="#display-inline-block（行内块级元素）" class="headerlink" title="display=inline-block（行内块级元素）"></a>display=inline-block（行内块级元素）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .inline-block-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">display</span>: inline-block;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;inline-block-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;inline-block-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;inline-block-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span> </span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/022.png" alt="022"></p>
            <p><code>display: inline-block</code>使用后<code>margin</code>不会穿透父元素，同时还需要解决如果两个inline-block在同一行，会有元素之间有空隙、元素上浮无法对齐的问题；<br>也可以作用在父元素上面，子元素<code>margin</code>属性不会穿透父元素，父元素也可能遇到上面两个问题；</p>
            <h3 id="display-table-cell（表格单元格）"><a href="#display-table-cell（表格单元格）" class="headerlink" title="display=table-cell（表格单元格）"></a>display=table-cell（表格单元格）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .table-cell-wrap&#123;</span><br><span class="line"><span class="css">    <span class="attribute">display</span>: table-cell;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .table-cell-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;table-cell-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;table-cell-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;table-cell-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span> </span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/023.png" alt="023"></p>
            <p>在父元素使用作为一个表格单元格，子元素<code>margin</code>属性不会穿透父元素；</p>
            <h3 id="display-table-caption（表格标题）"><a href="#display-table-caption（表格标题）" class="headerlink" title="display=table-caption（表格标题）"></a>display=table-caption（表格标题）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .table-caption-wrap&#123;</span><br><span class="line"><span class="css">    <span class="attribute">display</span>: table-caption;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .table-caption-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;table-caption-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;table-caption-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;table-caption-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span> </span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/024.png" alt="024"></p>
            <p>在父元素使用作为一个表格标题显示，子元素<code>margin</code>属性不会穿透父元素；</p>
            <h3 id="display-some-value（匿名表格单元格元素）"><a href="#display-some-value（匿名表格单元格元素）" class="headerlink" title="display=some value（匿名表格单元格元素）"></a>display=some value（匿名表格单元格元素）</h3>
            <blockquote>
              <p>元素的 <code>display</code>为 <code>table</code>、<code>table-row</code>、 <code>table-row-group</code>、<code>table-header-group</code>、<code>table-footer-group</code>（分别是HTML table、row、tbody、thead、tfoot的默认属性）或 <code>inline-table</code></p>
            </blockquote>
            <ul>
              <li><code>table</code>、<code>table-row</code>、 <code>table-row-group</code>、<code>table-header-group</code>、<code>table-footer-group</code> 的用法同<code>table-caption</code>，需要使用在父元素子元素才不会穿透父元素</li>
              <li><code>inline-table</code> 的用法同 <code>inline-block</code></li>
            </ul>
            <h3 id="overflow-visible"><a href="#overflow-visible" class="headerlink" title="overflow!=visible"></a>overflow!=visible</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .overflow-wrap--auto&#123;</span><br><span class="line"><span class="css">    <span class="attribute">overflow</span>: auto;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .overflow-wrap--hidden&#123;</span><br><span class="line"><span class="css">    <span class="attribute">overflow</span>: hidden;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .overflow-wrap--overlay&#123;</span><br><span class="line"><span class="css">    <span class="attribute">overflow</span>: overlay;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .overflow-wrap--scroll&#123;</span><br><span class="line"><span class="css">    <span class="attribute">overflow</span>: scroll;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .overflow-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;overflow-wrap overflow-wrap--auto&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;overflow-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;overflow-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/025.png" alt="025"></p>
            <ul>
              <li><code>overflow</code>属性为<code>auto</code> <code>hidden</code> <code>overlay</code> <code>scroll</code> 时触发bfc，其子元素<code>margin</code>不会穿透</li>
              <li>如果父元素为四个值时，当前元素可使用<code>inherit</code></li>
            </ul>
            <h3 id="display-flow-root"><a href="#display-flow-root" class="headerlink" title="display=flow-root"></a>display=flow-root</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .flow-root-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .clearfix&#123;</span><br><span class="line"><span class="css">    <span class="attribute">display</span>: flow-root;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="css">  <span class="keyword">@supports</span> <span class="keyword">not</span> (<span class="attribute">display</span>:flow-root) &#123; </span></span><br><span class="line"><span class="css">    <span class="selector-class">.clearfix</span><span class="selector-pseudo">::after</span>&#123;<span class="attribute">content</span>:<span class="string">&quot; &quot;</span>; <span class="attribute">display</span>:block; <span class="attribute">clear</span>:both; <span class="attribute">visibility</span>:hidden; <span class="attribute">height</span>:<span class="number">0</span>&#125; </span></span><br><span class="line"><span class="css">    <span class="selector-class">.clearfix</span>&#123;zoom:<span class="number">1</span>&#125; </span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;flow-root-wrap clearfix&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;flow-root-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;flow-root-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/026.png" alt="026"></p>
            <p><code>display: flow-root</code>只支持Firefox 53+、Chrome 58+、Opera 45+，通过<code>@supports</code>能支持Edge</p>
            <h3 id="contain-layout、content、strict"><a href="#contain-layout、content、strict" class="headerlink" title="contain=layout、content、strict"></a>contain=layout、content、strict</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .contain-wrap&#123;</span><br><span class="line"><span class="css">    contain: layout;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .contain-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;contain-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;contain-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;contain-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/027.png" alt="027"></p>
            <p>contain 属性允许开发者声明当前元素和它的内容尽可能的独立于 DOM 树的其他部分。 </p>
            <p>其中layout、content、strict 可触发BFC</p>
            <h3 id="display-flex、inline-flex（弹性元素）"><a href="#display-flex、inline-flex（弹性元素）" class="headerlink" title="display=flex、inline-flex（弹性元素）"></a>display=flex、inline-flex（弹性元素）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .flex-wrap&#123;</span><br><span class="line"><span class="css">    <span class="attribute">display</span>: flex;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .flex-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;flex-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;flex-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;flex-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/028.png" alt="028"></p>
            <p>当为<code>inline-flex</code>时遇到的问题同<code>inline-block</code></p>
            <h3 id="display-grid、inline-grid（网格元素）"><a href="#display-grid、inline-grid（网格元素）" class="headerlink" title="display=grid、inline-grid（网格元素）"></a>display=grid、inline-grid（网格元素）</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .grid-wrap&#123;</span><br><span class="line"><span class="css">    <span class="attribute">display</span>: grid;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .grid-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;grid-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;grid-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;grid-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/029.png" alt="029"></p>
            <p>当为<code>inline-grid</code>时遇到的问题同<code>inline-block</code></p>
            <h3 id="column-count、column-width-auto（多列容器）"><a href="#column-count、column-width-auto（多列容器）" class="headerlink" title="column-count、column-width!=auto（多列容器）"></a>column-count、column-width!=auto（多列容器）</h3>
            <p>元素的 column-count 或 column-width 不为 auto，包括 column-count 为 1</p>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .column-wrap&#123;</span><br><span class="line"><span class="css">    <span class="attribute">column-width</span>: <span class="number">200px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">column-count</span>: <span class="number">2</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .column-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;column-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;column-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;column-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/030.png" alt="030"></p>
            <p>虽然截图中margin超出body边界，实际情况确是没有。</p>
            <p>columns的使用方法见文末参考</p>
            <h3 id="column-span-all"><a href="#column-span-all" class="headerlink" title="column-span=all"></a>column-span=all</h3>
            <figure class="highlight html">
              <table>
                <tr>
                  <td class="gutter">
                    <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                  </td>
                  <td class="code">
                    <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">  *&#123;<span class="attribute">margin</span>:<span class="number">0</span>; <span class="attribute">padding</span>:<span class="number">0</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">html</span>&#123;<span class="attribute">background</span>: <span class="number">#f9fae2</span>;&#125;</span></span><br><span class="line"><span class="css">  <span class="selector-tag">body</span>&#123;<span class="attribute">background</span>: <span class="number">#cad9f2</span>;&#125;</span></span><br><span class="line">  </span><br><span class="line">  .column-span-wrap&#123;</span><br><span class="line"><span class="css">    <span class="attribute">column-span</span>: all;</span></span><br><span class="line">  &#125;</span><br><span class="line">  .column-span-el&#123;</span><br><span class="line"><span class="css">    <span class="attribute">width</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">height</span>: <span class="number">100px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">margin</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">    <span class="attribute">background</span>: <span class="number">#ff8d8d</span>;</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;column-span-wrap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;column-span-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;column-span-el&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                  </td>
                </tr>
              </table>
            </figure>
            <p><img src="" data-original="/images/css/031.png" alt="031"></p>
            <p>添加之后我行为异常</p>
            <h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2>
            <p>触发BFC主要有一些几个元素</p>
            <ul>
              <li>根元素：HTML</li>
              <li>float：不为none</li>
              <li>position：absolute、fixed</li>
              <li>display：inline-block、table、table-cell、table-caption、table-row、table-row-group、table-header-group、table-footer-group、inline-table、flow-root、flex、inline-flex、grid、inline-grid</li>
              <li>contain：layout、content、strict</li>
              <li>overflow：不为visible</li>
              <li>columns、column-count、column-width、column-span</li>
            </ul>
            <h2 id="应用场景"><a href="#应用场景" class="headerlink" title="应用场景"></a>应用场景</h2>
            <p>BFC的应用场景主要有一下几个方面，这里不做展开讨论，将单独写文章</p>
            <ul>
              <li><a href="../2019-01-09-solution-of-three-column-layout/">自适应三栏布局</a></li>
              <li><a href="../2019-01-04-clear-float/">清除内部浮动</a></li>
              <li><a href="../2019-01-17-preventing-vertical-margin-overlap/">防止垂直margin重叠</a></li>
              <li><a href="../2019-01-17-prevent-text-wrapping/">防止文字环绕</a></li>
            </ul>
            <h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1>
            <p><a target="_blank" rel="noopener" href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context">https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context</a><br><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Block_formatting_context">https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Block_formatting_context</a><br><a target="_blank" rel="noopener" href="https://www.w3.org/TR/CSS21/visuren.html#block-formatting">https://www.w3.org/TR/CSS21/visuren.html#block-formatting</a><br><a target="_blank" rel="noopener" href="https://drafts.csswg.org/css-display/#block-formatting-context">https://drafts.csswg.org/css-display/#block-formatting-context</a><br><a target="_blank" rel="noopener" href="https://blog.csdn.net/woshinannan741/article/details/51113612">https://blog.csdn.net/woshinannan741/article/details/51113612</a></p>
            <p><a target="_blank" rel="noopener" href="https://developer.mozilla.org/en-US/docs/Web/CSS/display">https://developer.mozilla.org/en-US/docs/Web/CSS/display</a><br><a target="_blank" rel="noopener" href="https://www.w3cplus.com/css3/display-flow-root.html">https://www.w3cplus.com/css3/display-flow-root.html</a><br><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/CSS/contain">https://developer.mozilla.org/zh-CN/docs/Web/CSS/contain</a><br><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/CSS/columns">https://developer.mozilla.org/zh-CN/docs/Web/CSS/columns</a><br><a target="_blank" rel="noopener" href="https://www.cnblogs.com/xinjie-just/p/5953386.html">https://www.cnblogs.com/xinjie-just/p/5953386.html</a></p>
            <p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/chen-cong/p/7862832.html">https://www.cnblogs.com/chen-cong/p/7862832.html</a><br><a target="_blank" rel="noopener" href="https://www.w3cplus.com/css/understanding-css-layout-block-formatting-context.html">https://www.w3cplus.com/css/understanding-css-layout-block-formatting-context.html</a></p>

          </div>





          <footer class="post-footer">
            <div class="post-tags">
              <a href="/tags/BFC/" rel="tag"># BFC</a>
              <a href="/tags/Block-Formatting-Context/" rel="tag"># Block Formatting Context</a>
            </div>



            <div class="post-nav">
              <div class="post-nav-item">
                <a href="/blob/2019-01-08-get-the-height-of-the-visible-area-on-the-page-screen/" rel="prev" title="获取网页屏幕可见区域高度">
                  <i class="fa fa-chevron-left"></i> 获取网页屏幕可见区域高度
                </a>
              </div>
              <div class="post-nav-item">
                <a href="/blob/2019-01-09-solution-of-three-column-layout/" rel="next" title="三栏布局的解决方案">
                  三栏布局的解决方案 <i class="fa fa-chevron-right"></i>
                </a>
              </div>
            </div>
          </footer>
        </article>
      </div>







      <script>
        window.addEventListener('tabs:register', () => {
          let {
            activeClass
          } = CONFIG.comments;
          if (CONFIG.comments.storage) {
            activeClass = localStorage.getItem('comments_active') || activeClass;
          }
          if (activeClass) {
            const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
            if (activeTab) {
              activeTab.click();
            }
          }
        });
        if (CONFIG.comments.storage) {
          window.addEventListener('tabs:click', event => {
            if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
            const commentClass = event.target.classList[1];
            localStorage.setItem('comments_active', commentClass);
          });
        }
      </script>
    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


      <div class="copyright">
        &copy;
        <span itemprop="copyrightYear">2021</span>
        <span class="with-love">
          <i class="fa fa-heart"></i>
        </span>
        <span class="author" itemprop="copyrightHolder">holidaypenguin</span>
      </div>
      <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
      </div>

    </div>
  </footer>


  <script size="300" alpha="0.1" zIndex="-1" src="https://cdn.jsdelivr.net/npm/ribbon.js@1.0.2/dist/ribbon.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
  <script src="/js/love.js"></script>

  <script src="/js/development.js"></script>
  <script src="/js/utils.js"></script>
  <script src="/js/motion.js"></script>
  <script src="/js/schemes/muse.js"></script>
  <script src="/js/next-boot.js"></script>


  <script src="/js/local-search.js"></script>









  <script>
    (function() {
      function leancloudSelector(url) {
        url = encodeURI(url);
        return document.getElementById(url).querySelector('.leancloud-visitors-count');
      }

      function addCount(Counter) {
        const visitors = document.querySelector('.leancloud_visitors');
        const url = decodeURI(visitors.id);
        const title = visitors.dataset.flagTitle;

        Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({
            url
          })))
          .then(response => response.json())
          .then(({
            results
          }) => {
            if (results.length > 0) {
              const counter = results[0];
              leancloudSelector(url).innerText = counter.time + 1;
              Counter('put', '/classes/Counter/' + counter.objectId, {
                  time: {
                    '__op': 'Increment',
                    'amount': 1
                  }
                })
                .catch(error => {
                  console.error('Failed to save visitor count', error);
                });
            } else {
              Counter('post', '/classes/Counter', {
                  title,
                  url,
                  time: 1
                })
                .then(response => response.json())
                .then(() => {
                  leancloudSelector(url).innerText = 1;
                })
                .catch(error => {
                  console.error('Failed to create', error);
                });
            }
          })
          .catch(error => {
            console.error('LeanCloud Counter Error', error);
          });
      }

      function showTime(Counter) {
        const visitors = document.querySelectorAll('.leancloud_visitors');
        const entries = [...visitors].map(element => {
          return decodeURI(element.id);
        });

        Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({
            url: {
              '$in': entries
            }
          })))
          .then(response => response.json())
          .then(({
            results
          }) => {
            for (let url of entries) {
              const target = results.find(item => item.url === url);
              leancloudSelector(url).innerText = target ? target.time : 0;
            }
          })
          .catch(error => {
            console.error('LeanCloud Counter Error', error);
          });
      }

      const {
        app_id,
        app_key,
        server_url
      } = {
        "enable": true,
        "app_id": "povuqNsSqFodlakVIwtEX5kb-gzGzoHsz",
        "app_key": "zXD40RDtDB3DMtpC89k0AK7g",
        "server_url": null,
        "security": false
      };

      function fetchData(api_server) {
        const Counter = (method, url, data) => {
          return fetch(`${api_server}/1.1${url}`, {
            method,
            headers: {
              'X-LC-Id': app_id,
              'X-LC-Key': app_key,
              'Content-Type': 'application/json',
            },
            body: JSON.stringify(data)
          });
        };
        if (CONFIG.page.isPost) {
          if (CONFIG.hostname !== location.hostname) return;
          addCount(Counter);
        } else if (document.querySelectorAll('.post-title-link').length >= 1) {
          showTime(Counter);
        }
      }

      const api_server = app_id.slice(-9) === '-MdYXbMMI' ? `https://${app_id.slice(0, 8).toLowerCase()}.api.lncldglobal.com` : server_url;

      if (api_server) {
        fetchData(api_server);
      } else {
        fetch('https://app-router.leancloud.cn/2/route?appId=' + app_id)
          .then(response => response.json())
          .then(({
            api_server
          }) => {
            fetchData('https://' + api_server);
          });
      }
    })();
  </script>



<script>
            window.imageLazyLoadSetting = {
                isSPA: false,
                preloadRatio: 1,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(n){n.imageLazyLoadSetting.processImages=o;var e=n.imageLazyLoadSetting.isSPA,i=n.imageLazyLoadSetting.preloadRatio||1,r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]"));function o(){e&&(r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")));for(var t,a=0;a<r.length;a++)0<=(t=(t=r[a]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(n.innerHeight*i||document.documentElement.clientHeight*i)&&function(){var t,e,n,i,o=r[a];t=o,e=function(){r=r.filter(function(t){return o!==t})},n=new Image,i=t.getAttribute("data-original"),n.onload=function(){t.src=i,e&&e()},t.src!==i&&(n.src=i)}()}o(),n.addEventListener("scroll",function(){var t,e;t=o,e=n,clearTimeout(t.tId),t.tId=setTimeout(function(){t.call(e)},500)})}(this);</script></body>

</html>